package com.joolun.weixin.config;

import com.joolun.common.config.ScrmConfig;
import com.joolun.framework.config.RedisConfig;
import me.chanjar.weixin.common.redis.RedisTemplateWxRedisOps;
import me.chanjar.weixin.cp.config.impl.WxCpTpRedissonConfigImpl;
import me.chanjar.weixin.cp.constant.WxCpApiPathConsts;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

/**
 * @author ：qiuzl
 * @date ：Created in 2022/4/8 17:33
 * @description：第三方的配置
 **/
@Component
public class WxCpTpConfiguration {

//    @Autowired
//    private RedissonClient redissonClient;
    @Autowired
    private StringRedisTemplate redisTemplate;

    @Value("${scrm.baseApiUrl:''}")
    private String baseApiUrl;

    public WxCpTpRedissonConfigImpl getBaseConfig(){
        return  WxCpTpRedissonConfigImpl.builder().baseApiUrl(WxCpApiPathConsts.DEFAULT_CP_BASE_URL)
                .suiteId(ScrmConfig.getMainSuiteID())
                .suiteSecret(ScrmConfig.getMainSuiteSecret())
                .token(ScrmConfig.getMainSuiteToken())
                .aesKey(ScrmConfig.getMainSuiteEncodingAESKey())
                .corpId(ScrmConfig.getExtCorpID())
                .corpSecret(ScrmConfig.getMainAgentSecret())
                .providerSecret(ScrmConfig.getProviderSecret())
                .keyPrefix(RedisConfig.SUITE_CONFIG)
                .baseApiUrl(baseApiUrl)
                //.wxRedisOps(new RedissonWxRedisOps(redissonClient)).build();
                .wxRedisOps(new RedisTemplateWxRedisOps(redisTemplate)).build();

    }

}
